package com.rc.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.rc.util.Util;
import com.telpoo.frame.ui.BaseActivity;

public class ForgotPass extends BaseActivity implements OnClickListener {

	private EditText txtEmail;
	private Button btRessetPass;

	public static void callIntent(Activity ct) {
		Intent it = new Intent(ct, ForgotPass.class);
		ct.startActivity(it);
		ct.finish();
	}

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main_reset_pass);

		// register
		txtEmail = (EditText) findViewById(R.id.txtEmail);
		btRessetPass = (Button) findViewById(R.id.btRessetPass);

		// funtion
		btRessetPass.setOnClickListener(this);
		txtEmail.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub
				Util.setVisiable(txtEmail);
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		switch (v.getId()) {
		case R.id.btRessetPass:
			if (validate()) {
				ForgotPassConfirm.callIntent(ForgotPass.this);
			}

			break;

		default:
			break;
		}
	}

	private boolean validate() {
		if (!Util.validateText(txtEmail)) {
			Util.setError((EditText) txtEmail, getString(R.string.input_email));
		} else if (!Util.validateEmail(txtEmail)) {
			Util.setError((EditText) txtEmail,
					getString(R.string.invalid_email));
		} else {
			return true;
		}
		return false;
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		Login.callIntent(ForgotPass.this);
	}

}
